import {
	getUserAuthor
} from '@/api/common.js';

const state = {
	pageLoading: false,
	confirmModal: {
		visible: false,
		text: '',
		callBack: null,
	},
	userAuthorList:[]
}

const actions = {
	async getUserAuthorAction({
		commit,
	}) {
		const res = await getUserAuthor();
		if (res.success && res.data) {
			let resullt = [];
			res.data.forEach(menu=>{
				const subMenu = menu.subMenu || [];
				if(subMenu.length){
					subMenu.forEach(item=>{
						resullt = [...resullt,...item.roles,item.path]
					})
				}
			})
			uni.setStorageSync('userAuthorList',resullt);
			commit('setUserAuthorList', resullt);
		}
	}
}

const mutations = {
	setPageLoading(state, data) {
		state.pageLoading = data
	},
	showConfirmModal(state, data) {
		state.confirmModal = {
			visible: true,
			text: data.text,
			callBack: data.success
		}
	},
	closeConfirmModal(state, data) {
		state.confirmModal = {
			visible: false,
			text: '',
			callBack: null
		}
	},
	setUserAuthorList(state, data){
		state.userAuthorList = data;
	}
}
export default {
	namespaced: true,
	state,
	actions,
	mutations
}